﻿//-----------------------------------------------------------------------
// <copyright file="SA1008.cs" company="c0x3y">
//     Copyright (c) c0x3y. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace c0x3y.StyleCopFixer.Errors
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using EnvDTE;
    using EnvDTE80;

    public static class SA1008
    {
        public static void Run(EnvDTE.DTE dte, ErrorItem selectedError)
        {
            selectedError.Navigate();
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);
            ep.StartOfDocument();
            while (!ep.AtEndOfDocument)
            {
                string testString = ep.GetLines(ep.Line, ep.Line + 1);
                if (Regex.IsMatch(testString, @"\(\s+"))
                {
                    testString = Regex.Replace(testString, @"\(\s+", @"(");
                    ep.ReplaceText(ep.LineLength, testString, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
                }

                ep.LineDown();
            }
        }
    }
}
